package com.shiliu.api.controller;

import com.shiliu.api.LoginControllerApi;
import com.shiliu.api.common.utils.JwtUtil;
import com.shiliu.model.pojo.ResponseResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * @description: TODO
 * @author: shili
 * @created: 2019/12/25 20:22
 * @version: v1.0.0
 */
@RestController
@RequestMapping("/api/v1")
public class LoginController extends BaseController implements LoginControllerApi {



    @Override
    @RequestMapping("/login")
    public ResponseResult login(String username, String password) {
        // 1.调用数据库查询用户名和密码是否正确
        // 2.正确生成token返回,测试使用5分钟,此代码应该写在service层
        String token = JwtUtil.generateToken("123456",username, 5 * 60 * 1000);
        ResponseResult ok = ResponseResult.ok("登录成功!", 10000);
        HttpServletResponse response = getResponse();
        response.setHeader("token",token);
        return ok;
    }
}
